package org.loneranger.p1_get_bean.demo;

import org.loneranger.p1_get_bean.bean.MyRabbit;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.function.Supplier;

/**
 * supplier的方式获取bean
 * @author loneranger
 */
public class SupplierBeanTest {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.registerBean("rabbit",MyRabbit.class, new Supplier<MyRabbit>() {
            @Override
            public MyRabbit get() {
                MyRabbit myRabbit = new MyRabbit();
                myRabbit.setAge(2);
                myRabbit.setName("兔兔");
                return myRabbit;
            }
        });

        applicationContext.refresh();

        MyRabbit rabbit = applicationContext.getBean("rabbit", MyRabbit.class);
        rabbit.tiao();


    }

}
